package com.lu.task.instance;

//import com.lu.common.utils.UnMailUtils;
import com.lu.common.utils.MailUtils;
import com.lu.task.domain.TaskDO;
import com.lu.task.service.TaskService;
import org.quartz.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MailJob implements Job{

    @Autowired
    private TaskService taskService;

    @Override
    public void execute(JobExecutionContext context) throws JobExecutionException {
        JobDetail jobDetail = context.getJobDetail();
        JobKey jobKey = jobDetail.getKey();
        String jobGroup = jobKey.getGroup();
        String jobName = jobKey.getName();
        Map<String,Object> map = new HashMap<>();
        map.put("jobGroup",jobGroup);
        map.put("jobName",jobName);
        map.put("jobStatus",1);
        List<TaskDO> list = taskService.list(map);
        for(TaskDO l : list){
//            String content = l.getContent();
//            l.getTemplate();
            new MailUtils().sendHtmlEmail(l.getSrcEmail(),l.getSrcEmailPassword(),l.getTargetEmail(),l.getSubject(),l.getContent());
        }
    }
}
